//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __ELASTOS_GRAFIX_ENGINE_H__
#define __ELASTOS_GRAFIX_ENGINE_H__

#define _NO_CSURFACE_CLASSOBJECT_
#define _NO_CWINDOW_CLASSOBJECT_
#define _NO_CWINDOWENUMERATOR_CLASSOBJECT_
#define _NO_CLAYER_CLASSOBJECT_
#define _NO_CGFXENGINE_CLASSOBJECT_
#define _NO_CGFXFONT_CLASSOBJECT_
#define _NO_CEVENTBUFFER_CLASSOBJECT_

#define DUMPSTACK           DEBUGLEVEL
#define DEBUG_BUFFERREF     DEBUGLEVEL
#define DEBUG_BUFFERSIZE    DEBUGLEVEL
#define DEBUG_LOCK          DEBUGLEVEL
#define DEBUG_DESTRUCTOR    DEBUGLEVEL
#define DEBUG_ANIMATION     DEBUGLEVEL
#define DEBUG_PAINT         DEBUGLEVEL

#define COLOR_TRANSPARENT   0x00000000

#include <elatypes.h>

#include <ddk.h>
#ifdef _zener
#include <mantle.h>
#endif

#ifdef _win32
#ifdef _pc
#include <elapi.h>
#include <elasysapi.h>
#include <stdio.h>
#include <stdlib.h>
#endif
#endif

#ifdef _wince
#include <aura.h>
#endif

#include <linknode.h>
#include <vkey.h>
#include <display.h>
#include <math.h>

#include "baseaction.h"

extern void Nu_DmaBufFree(physaddr_t ptr, size_t size);
extern void *Nu_DmaBufAlloc(size_t size, Int32 bUserAccess);

#ifndef _zener
#define PAGE_MASK (~(PAGE_SIZE - 1))

inline UInt32 AlignPageDown(UInt32 n)
{
    return n & PAGE_MASK;
}

inline UInt32 AlignPageUp(UInt32 n)
{
    return (n + PAGE_SIZE - 1) & PAGE_MASK;
}
#endif // _zener


#include "grafixcomm.h"
#include "lib\fusion.h"
#include "lib\region.h"
#include "lib\rectangle.h"
#include "lib\specialclip.h"
#include "lib\pixelformat.h"

#include "lib\lock.h"
#include "lib\list.h"
#include "core\grafixobjectstack.h"
#include "core\buffercache.h"
#include "core\baseaction.h"

class RectangleLink : public DLinkNode {
public:
    RectangleLink() {
        Initialize();
        m_free = TRUE;
        m_rect.x = 0;
        m_rect.y = m_rect.width = m_rect.height = -1;
    }

    ~RectangleLink();

public:
    ECode PreciseAdd(
        /* [in] */ Region* region);

    ECode PreciseRemove(
        /* [in] */ Region* region);

    ECode PreciseAdd(
        /* [in] */ Rectangle* rectangle);

    ECode PreciseRemove(
        /* [in] */ Rectangle* rectangle);

    ECode Clone(
        /* [in] */ RectangleLink* header);

    Void RemoveAll();

    Boolean Equal(
        /* [in] */ RectangleLink* header);

    Boolean IsEmpty() {
        assert(!RectangleValid(&m_rect) && m_free);

        return (0 == m_rect.x);
    }

private:
    ECode Add(
        /* [out] */ Rectangle* rect);

public:
    Rectangle m_rect;
    Boolean m_free;
};

#define IncrementDllLockCount()         do {} while(0)
#define DecrementDllLockCount()         do {} while(0)

#include "..\core\CGrafixEventBuffer.h"
#include "..\core\CGrafixObject.h"
#include "..\core\CGrafixEngine.h"
#include "..\core\CGrafixLayer.h"
#include "..\core\CGrafixObjectEnumerator.h"
#include "..\core\CGrafixSurface.h"

extern VinciLock g_lock;

#define GhostWidth      4
#define GhostHeight     4

#if defined(_C28) && defined(_arm)
#define CURSOR_VISIBLE
#define CURSOR_COLOR 0xFFFF0000
#endif

#if 0
extern Address g_virAddr;

INLINE Void InitTimer()
{
    EzIoRemap(0, 4096, 0x40A00000, Map_Private, Protect_RWIO, &g_virAddr);
}

INLINE UInt32 GetTicks()
{
    return (*(unsigned long *)(g_virAddr + 0x10));
}

#else
#define InitTimer()
#define GetTicks() 0
#endif // 0

#ifndef PAGE_SHIFT
#define PAGE_SHIFT (12)
#endif

#define MAX_WINDOW_SIZE (1024 * 1024)

#define MAX_SAME_BUFFER_COUNT (2)

INLINE UInt32 PageAround(UInt32 size) {
    return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
}

extern BufferCache  g_bufferCache;

#endif  // __ELASTOS_GRAFIX_ENGINE_H__
